/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.common.model.DistributionProdBind;
import com.yami.shop.distribution.common.service.DistributionProdBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author xwc
 * @date 2019-04-22 10:01:44
 */
@RestController
@RequestMapping("/distribution/distributionProdBind")
@Api(tags = "平台端分销商品绑定表接口")
public class DistributionProdBindController {

    @Autowired
    private DistributionProdBindService distributionProdBindService;

    @GetMapping("/page")
    @ApiOperation(value = "分页获取分销商品绑定信息列表")
    public ServerResponseEntity<IPage<DistributionProdBind>> getDistributionProdBindPage(PageParam<DistributionProdBind> page,
                                                                                   DistributionProdBind distributionProdBind) {
        return ServerResponseEntity.success(distributionProdBindService.page(page, new LambdaQueryWrapper<DistributionProdBind>()));
    }

    @GetMapping("/info/{id}")
    @ApiOperation(value = "通过id查询分销商品绑定表")
    @ApiImplicitParam(name = "id", value = "分销商品绑定id", required = true, dataType = "Long")
    public ServerResponseEntity<DistributionProdBind> getById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(distributionProdBindService.getById(id));
    }

    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:save')")
    @ApiOperation(value = "新增分销商品绑定表")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid DistributionProdBind distributionProdBind) {
        return ServerResponseEntity.success(distributionProdBindService.save(distributionProdBind));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:update')")
    @ApiOperation(value = "修改分销商品绑定表")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionProdBind distributionProdBind) {
        return ServerResponseEntity.success(distributionProdBindService.updateById(distributionProdBind));
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:delete')")
    @ApiOperation(value = "通过id删除分销商品绑定表")
    @ApiImplicitParam(name = "id", value = "分销商品绑定id", required = true, dataType = "Long")
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ServerResponseEntity.success(distributionProdBindService.removeById(id));
    }
}
